<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="skladiscenje.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <META http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>SKLADISCENJE systems</title>
        <LINK href="CSS/style.css" rel="stylesheet" type="text/css" />
        <LINK REL="SHORTCUT ICON" HREF="images/favicon.ico" />
    </head>
        
    <body>
		<table id="wrapper">
			<tr>
				<td>
                	<table border="0"  align="center" cellspacing="0" cellpadding="0">
                    	<tr>
                            <td class="login_top"></td>
                        </tr>
                        <tr>
                            <td class="login_middle_bg">
                            	<%
								if (request.getParameter("prijava") != null){
									if (request.getParameter("prijava").equals("failed")){
										%>
										<table class="opozoriloNapaka" width="50%" align="center">
									    	<tr>
									            <td>
									            Napačno uporabniško ime ali geslo!
									            </td>
									        </tr>
									    </table><br />
										<%
									}
									if (request.getParameter("prijava").equals("potrebna")){
										%>
										<table class="opozoriloNapaka" width="50%" align="center">
									    	<tr>
									            <td>
									            Potrebna je prijava!
									            </td>
									        </tr>
									    </table><br />
										<%
									}
								}
                            	%>
                                <form name="prijava" method="post" action="";>
                                    <table align="center" cellpadding="3" cellspacing="3">
                                        <tr>
                                            <td class="login_text">UPORABNIŠKO IME :</td>
                                            <td><input type="text" name="uime" /></td>
                                        </tr>
                                        <tr>
                                            <td class="login_text">GESLO :</td>
                                            <td><input type="password" name="geslo" /></td>
                                        </tr>
                                        <tr>
                                            <td align="center" colspan="2"><input type="submit" name="potrdiPrijavo" value="Prijava" /></td>
                                        </tr>
                                    </table>
                                </form>
                                <%
                                if(request.getParameter("potrdiPrijavo") != null){
                                	if ((request.getParameter("uime") != null) && (request.getParameter("geslo") != null)) {
		                                String id = Evidenca.preveriUporabnika(request.getParameter("uime"),request.getParameter("geslo"));
		                                if(id.equals("failed"))
		                                	response.sendRedirect("index.jsp?prijava=failed");
		                                else{
		                                	Uporabnik uporabnik = Evidenca.getUporabnikByID(Integer.parseInt(id));
		                                	session.setAttribute("uporabnik", uporabnik);
		                					session.setMaxInactiveInterval(600);
		                					response.sendRedirect("main.jsp");
		                                }
                                	}else{
                                		response.sendRedirect("index.jsp?prijava=failed");
                                	}
                                }
                                %>
                            </td>
                        </tr>
                        <tr>
                            <td class="login_bottom"></td>
                        </tr>
                    </table>
                </td>
			</tr>
		</table>
	</body>
</html>
